package a.one.dimensional.array;
import java.util.Scanner;

/**
 * @author shkstart
 * @date 2022/4/16 - 18:03
 */

//1.使用Scanner，读取学生个数
//2.创建数组，存储学生成绩：动态初始化
//3.给数组中的元素赋值
//4.获取元素中的最大值
//5.根据每个学生成绩与最高分的差值，得到每个学生的等级，并输出等级和成绩
//    3和4一次完成方法
    /*		System.out.println("请输入" + number + "个学生成绩：");
		int maxScore = 0;
		for(int i = 0;i < scores.length;i++){
			scores[i] = scanner.nextInt();
			//4.获取数组中的元素的最大值:最高分
			if(maxScore < scores[i]){
				maxScore = scores[i];
			}
		}*/
//    老师第5步的优化 与自己对比
    /*  char level;
		for(int i = 0;i < scores.length;i++){
			if(maxScore - scores[i] <= 10){
				level = 'A';
			}else if(maxScore - scores[i] <= 20){
				level = 'B';
			}else if(maxScore - scores[i] <= 30){
				level = 'C';
			}else{
				level = 'D';
			}

			System.out.println("student " + i +
					" score is " + scores[i] + ",grade is " + level);*/
public class ArrayDemo01 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入学生个数：");
        int length = scan.nextInt();

        int[] scores = new int[length];
        System.out.println("请输入" + length + "个学生的成绩");
        for (int i = 0; i < scores.length; i++ ) {
//            int temp = scan.nextInt();
//            scores[i] = temp;
//            temp = 0;                        给数组赋值  自己的做法
            scores[i] = scan.nextInt(); //老师的做法
        }

        int max = scores[0];
        for (int i = 1; i < scores.length; i++ ) {
            if( scores[i] > max ) {
                max = scores[i];
            }
        }
        System.out.println("成绩最高为：" + max);

        for (int i = 0; i < length; i++ ) {
            if(scores[i] >= max - 10) {
                System.out.println("student " + i + " score is " + scores[i] + " grade is A");
            }else  if(scores[i] >= max - 20) {
                System.out.println("student " + i + " score is " + scores[i] + " grade is B");
            }else  if(scores[i] >= max - 30) {
                System.out.println("student " + i + " score is " + scores[i] + " grade is C");
            }else  {
                System.out.println("student " + i + " score is " + scores[i] + " grade is D");
            }
        }
    }
}
